﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LabTurtorial
{
    public partial class Lab06Adodemo : Form
    {
        private SqlCommand command;
        private SqlConnection connection;
        private string strConnect = "Data Source = localhost\\sqlexpress;database = EBILLINGANDINVOICESYSTEM;user id = sa; password = 13021988 ";
        private string strSelectUser = "SELECT Username,Password FROM [User]";
        public Lab06Adodemo()
        {
            InitializeComponent(); 
                                        
        }
        //private void GetConnectionDB() {
        //    connection = new SqlConnection(strConnect);            
        //}

        private void btnFetchList_Click(object sender, EventArgs e)
        {
            using (connection = new SqlConnection(strConnect)) {                
                using(command = new SqlCommand(strSelectUser,connection)){
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        int rows = 0;
                        //Iterate through records in the result set
                        while (reader.Read())
                        {
                            listView1.Items.Add(reader.GetString(0));
                            listView1.Items[rows].SubItems.Add(reader.GetString(1).ToString());
                            rows++;
                        }
                    }
                    catch(Exception ex) {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            
        }

    }
}
